define(['jquery', 'bootstrap', 'backend',"highcharts",'echarts','table','form'], function ($, undefined, Backend,Highcharts,echarts, Table, Form) {
    var basedObj=null;
    var propertyObj=null;
    var table2Obj=null;
    var labObj=null;
    var table3Obj=null;
    var searchflag1 = false;
    var searchflag2 = true;
    Date.prototype.Format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "H+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
    };
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'resources/resc/index',
                    add_url: 'resources/resc/add',
                    edit_url: 'resources/resc/edit',
                    del_url: 'resources/resc/del',
                    multi_url: 'resources/resc/multi',
                    import_url: 'resources/resc/import',
                    table: 'device',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'ip', title: __('Ip'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'port', title: __('Port'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'community', title: __('Community'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'area.mergename', title: __('Area_id'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'tag.name', title: __('局点'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'SysName', title: __('SysName'),operate:'LIKE',placeholder: __('模糊查询'),formatter:function(data,full){
                                if(data == "" || data == null){
                                    return "-";
                                }else{
                                    return data;
                                }
                            }},
                        {field: 'collectionagent_device.collectionagent_id', title: __('Choice Agent'), visible:false, searchList: $.getJSON("resources/Resc/getAgentSource")},
                        {field: 'agent_id', title: __('Choice Agent'),operate: false,formatter : Controller.api.formatter.tags,table: table, events:
                            {'click .labelhref':function(e,value,row){
                                // var ids = $(this).attr('tag_iff'); 
                                var ids = row.agent_ids;
                                // console.log(ids);
                                Backend.api.closetabs('/admin/proxy/agent/index?ids='+ids);
                                Backend.api.addtabs('/admin/proxy/agent/index?ids='+ids,'采集代理','fa fa-database');
                                }
                            }
                        },
                        {field: 'device_type', title: __('Device Type'),searchList:deviceTypeList},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons: [
                            /*{
                                name: 'addtabs',
                                text: '详情',
                                title: '资源详情',
                                classname: 'btn btn-xs btn-info btn-addtabs',
                                icon: 'fa fa-folder-o',
                                url: 'resources/resc/addtabs'
                            },*/
                            {
                                name: 'addtabs',
                                text: '设备监控',
                                title: '设备监控',
                                classname: 'btn btn-xs btn-info btn-addtabs',                                
                                icon: 'fa fa-database',                                
                                // icon: 'fa fa-folder-o',                              
                                url: 'region/device/index'
                            }
                        ]}
                    ]
                ]
            });
            // console.log($(".btn-delone").attr('data-original-title','删除aaaa'));

            // 为表格绑定事件
            Table.api.bindevent(table);

           

        },
        addtabs: function(){
            // 初始化表格参数配置
            Table.api.init();    
            
            $("#ifIndex").val("").trigger("change");//清空
            $(".flow_push").click(function(obj){
                var btn_obj = $(this);
                $.ajax({
                    url: 'general/screens/index',
                    type:'post',
                    //data: {ids:tag_id,names:names,starttime:starttime3,endtime:endtime3,gradename:gradename3},
                    dataType:'json',
                    success:function(json){
                        if(json.total<1){
                            Toastr.error("请先到屏幕维护-配置屏幕页面，配置屏幕名称");
                        }else{
                           var if_id = $(btn_obj).attr('if_id');
                           Fast.api.open("resources/tag/add_screen/ids/"+if_id+"?from=interface","选择屏幕");
                        }
                    }
                });
                
            });
            
            var a = $("#ids").html();
            var initCpuPageref = function(type){
                //获取ID
                var a2 = $("#ids").html();
                /*var starttime2='';
                var curDate = new Date();
                var start_date2 = new Date(curDate.getTime() - 24*60*60*1000).Format("yyyy-MM-dd HH:mm");; //前一天
                var end_date2 = new Date().Format("yyyy-MM-dd HH:mm");
                if(type=='1'){//重置
                   $("#start_date2").val(start_date2);
                   $("#end_date2").val(end_date2);
                   document.getElementById("gradename2")[0].selected=true;
                }
                if($("#start_date2").val() != ''){
                   starttime2=$("#start_date2").val();
                }else{
                    starttime2=start_date2;
                }
                var endtime2='';
                if($("#end_date2").val() != ''){
                   endtime2=$("#end_date2").val();
                }else{
                    endtime2=end_date2;
                }
                if (endtime2 < starttime2) {
                      layer.alert('结束时间应大于开始时间',{offset: ['200px', '150px']});
                    return false;
                }
                var gradename2='';
                if($("#gradename2").val() != "") {
                   gradename2=$("#gradename2").find("option:selected").val();
                }*/
                var starttime2 = $("#info_left").html();
                var endtime2=$("#info_right").html();
                var gradename2='';
                $.ajax({
                    url: 'resources/resc/firstCpu',
                    type:'post',
                    data: {ids:a2,starttime:starttime2,endtime:endtime2,gradename:gradename2},
                    dataType:'json',
                    success:function(json){
                        $('#slider').dateRangeSlider('resize');      
                        for(var item of json) { // item代表数组里面的元素
                            Controller.piechart(item, item.name, "propertylink","propertylinkname");
                        };
                    }
                });
            };
            if(Fast.api.query('supplier')){
                $('#bandwidth_supplier').selectpicker('val',Fast.api.query('supplier').split(','));
            }
            require(['bootstrap-select', 'bootstrap-select-lang'], function () {
                $('.selectpicker').selectpicker('refresh');
            });

            //initCpuPageref('0');
            var initPageref = function(type){
                /*var starttime='';
                var curDate = new Date();
                var start_date = new Date(curDate.getTime() - 24*60*60*1000).Format("yyyy-MM-dd HH:mm");; //前一天
                var end_date = new Date().Format("yyyy-MM-dd HH:mm");
                if(type=='1'){//重置1
                   $("#start_date").val(start_date);
                   $("#end_date").val(end_date);
                    document.getElementById("gradename")[0].selected=true;
                    $("#ifIndex").val("").trigger("change");//清空
                    $('.selectpicker').selectpicker('refresh'); 
                }
                if($("#start_date").val() != ''){
                   starttime=$("#start_date").val();
                }else{
                    starttime=start_date;
                }
                var endtime='';
                if($("#end_date").val() != ''){
                   endtime=$("#end_date").val();
                }else{
                    endtime=end_date;
                }
                if (endtime < starttime) {
                      layer.alert('结束时间应大于开始时间',{offset: ['200px', '150px']});
                    return false;
                }
                var gradename='';
                if($("#gradename").val() != "") {
                   gradename=$("#gradename").find("option:selected").val();
                }
                var alias='';
                if($("#alias").val() != "") {
                    alias=$("#alias").val();
                }
                var desc='';
                if($("#desc").val() != "") {
                    desc=$("#desc").val();
                }
                var ifIndex = "";
                if ($("#ifIndex").val() != "") {
                    ifIndex=$("#ifIndex").val();                   
                }*/
                // $.ajax({
                //     url: 'resources/resc/first',
                //     type:'post',
                //     data: {ifIndex:ifIndex,ids:a,starttime:starttime,endtime:endtime,gradename:gradename},
                //     dataType:'json',
                //     success:function(json){      
                //         $n = 1;
                //         for(var item of json) { // item代表数组里面的元素
                //             $("#basedlink_"+$n).show();
                //             console.log(item.name)
                //             $("#flow_push_"+$n).attr("if_id", item.id);
                //             Controller.piechart(item, item.name, "basedlink_"+$n);
                //             $n++;  
                //         };
                //         while($n<6){
                //             $("#basedlink_"+$n).hide();
                //             $n++;
                //         }
                //         if(basedObj!=null){//判断计时器是否为空
                //             window.clearInterval(basedObj);
                //             basedObj=null;
                //         } 
                //         basedObj=setInterval(function(){
                //           getPageref(1,starttime,endtime,gradename);
                //         },10100);
                //     }
                // });
                var alias='';
                var desc='';
                var ifIndex = "";
                var starttime = $("#info_left").html();
                var endtime=$("#info_right").html();
                var gradename='';
                //先获取总页数画图
                $.ajax({
                    url: 'resources/resc/fenye',
                    type:'post',
                    data: {alias:alias,desc:desc,ifIndex:ifIndex,ids:a,starttime:starttime,endtime:endtime,gradename:gradename},
                    dataType:'json',
                    success:function(json){      
                        //console.log(json) ;//没有数据   
                        if(json === -1){
                            $n = 1;
                            while($n<11){
                                $("#basedlink_"+$n).hide();
                                $("#flow_push_"+$n).hide();
                                $n++;
                            }
                            $("#pagination").hide();
                        }else{
                            $("#pagination").show();
                           var pageObj = new Page({
                                id: 'pagination',
                                pageTotal: json.pageTotal, //必填,总页数
                                pageAmount: 10,  //每页多少条
                                dataTotal: json.dataTotal, //总共多少条数据
                                curPage:1, //初始页码,不填默认为1
                                pageSize: 10, //分页个数,不填默认为5
                                showPageTotalFlag:true, //是否显示数据统计,不填默认不显示
                                showSkipInputFlag:true, //是否支持跳转,不填默认不显示
                                getPage: function (page) {
                                   //获取ID
                                    $.ajax({
                                        url: 'resources/resc/chart_data',
                                        type:'post',
                                        data: {alias:alias,desc:desc,ifIndex:ifIndex,page:page,ids:a,starttime:starttime,endtime:endtime,gradename:gradename},
                                        dataType:'json',
                                        success:function(json){
                                            /*if(basedObj!=null){//判断计时器是否为空
                                                window.clearInterval(basedObj);
                                                basedObj=null;
                                            } 
                                            basedObj=setInterval(function(){
                                              getPageref(page,starttime,endtime,gradename);
                                            },10300);*/
                                            $('#slider').dateRangeSlider('resize');
                                            $n = 1;
                                            for(var item of json) { // item代表数组里面的元素
                                                $("#basedlink_"+$n).show();
                                                $("#flow_push_"+$n).show();
                                                $("#flow_push_"+$n).attr("if_id", item.id);
                                                Controller.piechart(item, item.name, "basedlink_"+$n,"basedlinkname_"+$n);
                                                $n++;  
                                            };

                                            while($n<11){
                                                $("#basedlink_"+$n).hide();
                                                $("#flow_push_"+$n).hide();
                                                $n++;
                                            }
                                        }
                                    });
                                },
                            });

                            pageObj.getPage(1)
                        }
                    }
                });
            };
            
            var dateDff=function(endTime,startTime){
                //var date = enddate.getTime() - startdate.getTime();
                var usedTime  = new Date(endTime).getTime() - new Date(startTime).getTime();
                var year = Math.floor(usedTime / (365 *24 * 3600 * 1000)); // 计算出年数
                var leavel = usedTime % (365 *24 * 3600 * 1000); // 计算年数后剩余的时间
                
                var months = Math.floor(leavel / (30 *24 * 3600 * 1000)); // 计算出月数
                var leavel1 = leavel % (30 *24 * 3600 * 1000); // 计算月数后剩余的时间
                
                var days = Math.floor(leavel1 / (24 * 3600 * 1000)); // 计算出天数
                var leavel2 = leavel1 % (24 * 3600 * 1000); // 计算天数后剩余的时间
                
                var hours = Math.floor(leavel2 / (3600 * 1000)); // 计算剩余的小时数
                var leavel3 = leavel2 % (3600 * 1000); // 计算剩余小时后剩余的毫秒数
                
                var minutes = Math.floor(leavel3 / (60 * 1000)); // 计算剩余的分钟数
                var leavel4 = leavel3 % (60 * 1000); // 计算剩余分钟后剩余的毫秒数
                
                var seconds = Math.floor(leavel4 / (1000)); // 计算剩余的秒数
                var timename='';
                var time1= year+'年'+months+'月' +days+ '天' + hours + '时' + minutes + '分';
                if(year!=0){timename=year+'y';}
                if(months!=0){timename=timename+' '+months+'m';}
                if(days!=0){timename=timename+' '+days+'d';}
                if(hours!=0){timename=timename+' '+hours+'h';}
                return timename;
            };
            var initJQDateRange = function(){
                require(['jquery-ui', 'jQDateRangeSlider'], function () {
                    var curDate = new Date();     
                    var start_date=new Date(curDate);     
                    var end_date=new Date(curDate);
                   
                    $("#slider").dateRangeSlider();
                    $("#slider").dateRangeSlider("bounds", new Date(start_date.setSeconds(start_date.getSeconds()-zoomListarr['所有'])), new Date(curDate));
                    $("#slider").dateRangeSlider("min", new Date(end_date.setSeconds(end_date.getSeconds()-86400)));
                    $("#slider").dateRangeSlider("max", new Date(curDate));
                    $('.links>.link').attr("style", 'font-size: 10px; font-weight: normal; text-decoration: none;');
                    var a=$('.links>.link');
                    for (var i = 0; i < a.length; i++) {
                        if(a[i].innerText=='1d'){
                            $('.links>.link')[i].style.fontSize="11px";
                            $('.links>.link')[i].style.fontWeight="bold";
                        }
                    }
                    document.getElementById("info_period").innerText ='1d';
                    document.getElementById("info_left").innerText =end_date.Format("yyyy-MM-dd HH:mm:ss");
                    document.getElementById("info_right").innerText =curDate.Format("yyyy-MM-dd HH:mm:ss");
                    $(".ui-rangeSlider-handle.ui-rangeSlider-rightHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    $(".ui-rangeSlider-handle.ui-rangeSlider-leftHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    $(".ui-rangeSlider-label.ui-rangeSlider-rightLabel")[0].style.display="none";
                    $(".ui-rangeSlider-label.ui-rangeSlider-leftLabel")[0].style.display="none";
                });
            };
            require(['jquery-ui', 'jQDateRangeSlider'], function () {
                $("#slider").bind("userValuesChanged", function(e, data){
                    document.getElementById("info_left").innerText =new Date(data.values.min).Format("yyyy-MM-dd HH:mm:ss");
                    document.getElementById("info_right").innerText =new Date(data.values.max).Format("yyyy-MM-dd HH:mm:ss");
                    var hrefs=$('#tabs>li.active>a').attr("href");
                    if(hrefs == "#four"){
                       initCpuPageref('0');
                    }else if(hrefs == "#third"){
                       initPageref('0');
                    }   

                 
                });
                $("#statelink").click(function(){
                     if($(this).html()=="固定的"){
                        $("#statelink").html("动态的");
                     }else{
                        $("#statelink").html("固定的");
                     }
                     
                });
                $(".link").click(function(){
                     
                      var flag=true;
                      var aa=$("#slider").dateRangeSlider("values");
                      var maxDateTime=new Date(aa.max);
                      var minDateTime=new Date(aa.min);
                      var currDate = new Date();
                      if($(this).attr("nav") == undefined){//上方扩展时间轴
                            $('.links>.link').attr("style", 'font-size: 10px; font-weight: normal; text-decoration: none;');
                            $(this).attr("style", 'font-size: 11px; font-weight: bold; text-decoration: none;');            
                            //时间转换，规则移动最小时间(扩大时间)
                            var changeValue = parseFloat("-"+$(this).attr("zoom"));
                            //设置进度条位置
                            minDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                            maxDateTime=new Date(aa.max);
                            minDateTime = new Date(minDateTime);
                            document.getElementById("info_period").innerText =this.innerText;

                      }else{ //左移右移事件
                            //时间转换，加一天
                            var changeValue = parseFloat($(this).attr("nav"));
                            
                            if($("#statelink").html()=="动态的"){//时间间隔改变
                                //设置进度条位置
                                if(changeValue>0){
                                    maxDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                                    maxDateTime=new Date(maxDateTime);
                                    if(new Date(currDate).getTime()<new Date(maxDateTime).getTime()){
                                        layer.msg('调整时间超出范围');
                                        flag = false;
                                        //maxDateTime=currDate;
                                    }
                                }else{
                                    minDateTime=minDateTime.setSeconds(minDateTime.getSeconds()+changeValue);
                                    minDateTime=new Date(minDateTime);
                                    var currDatemin = currDate.setSeconds(currDate.getSeconds()-zoomListarr['所有']);
                                    if(new Date(currDatemin).getTime()>new Date(minDateTime).getTime()){
                                       layer.msg('调整时间超出范围');
                                       //minDateTime=new Date(currDatemin);
                                       flag = false;
                                    }
                                }
                                if (flag == true){
                                    var periodname=dateDff(maxDateTime,minDateTime);
                                    document.getElementById("info_period").innerText=periodname;
                                }
                            }else{//时间间隔固定
                                    maxDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                                    maxDateTime=new Date(maxDateTime);
                                    if(new Date(currDate).getTime()<new Date(maxDateTime).getTime()){
                                        layer.msg('调整时间超出范围');
                                        flag = false;
                                    }
                                    minDateTime=minDateTime.setSeconds(minDateTime.getSeconds()+changeValue);
                                    minDateTime=new Date(minDateTime);
                                    var currDatemin = currDate.setSeconds(currDate.getSeconds()-zoomListarr['所有']);
                                    if(new Date(currDatemin).getTime()>new Date(minDateTime).getTime()){
                                       layer.msg('调整时间超出范围'); 
                                       flag = false;
                                    }
                            }             
                                   
                      }    
                      if (flag == true){
                          $("#slider").dateRangeSlider("min", minDateTime);
                          $("#slider").dateRangeSlider("max", maxDateTime);
                          //设置右上方时间显示doc
                          document.getElementById("info_left").innerText =minDateTime.Format("yyyy-MM-dd HH:mm:ss");
                          document.getElementById("info_right").innerText =maxDateTime.Format("yyyy-MM-dd HH:mm:ss");
                          /*var hrefs=$('#tabs>li.active>a').attr("href");
                          if(hrefs == "#four"){
                               initCpuPageref('0');
                           }else if(hrefs == "#third"){
                               initPageref('0');
                          }*/

                          
                      }
                });
            });
            //initPageref('0');
            // 搜索
           /* $("#search_task").click(function(){
                initPageref('0');
            })
            //  重置
            $("#reset_task").click(function(){    
                initPageref('1');
            })
            // 搜索
            $("#search_task2").click(function(){
              initCpuPageref('0');
            })
            //  重置
            $("#reset_task2").click(function(){    
              initCpuPageref('1');  
            })*/
            
            var getPageref = function(page,starttime,endtime,gradename){
                   //获取ID
                    $.ajax({
                        url: 'resources/resc/chart_data',
                        type:'post',
                        data: {page:page,ids:a,starttime:starttime,endtime:endtime,gradename:gradename},
                        dataType:'json',
                        success:function(json){
                            $('#slider').dateRangeSlider('resize');
                            $n = 1;
                            for(var item of json) { // item代表数组里面的元素
                                Controller.piechart(item, item.name, "basedlink_"+$n,"basedlinkname_"+$n);
                                $n++;  
                            };
                        }
                    });
            };
            var getjQDateRange = function(){
                require(['jquery-ui', 'jQDateRangeSlider'], function () {
                    var curDate = new Date();     
                    var start_date=new Date(curDate);     
                    var end_date=new Date(curDate);
                   
                    $("#slider").dateRangeSlider();
                    $("#slider").dateRangeSlider("bounds", new Date(start_date.setSeconds(start_date.getSeconds()-zoomListarr['所有'])), new Date(curDate));
                    $("#slider").dateRangeSlider("min", new Date(end_date.setSeconds(end_date.getSeconds()-86400)));
                    $("#slider").dateRangeSlider("max", new Date(curDate));
                    $('.links>.link').attr("style", 'font-size: 10px; font-weight: normal; text-decoration: none;');
                    var a=$('.links>.link');
                    for (var i = 0; i < a.length; i++) {
                        if(a[i].innerText=='1d'){
                            $('.links>.link')[i].style.fontSize="11px";
                            $('.links>.link')[i].style.fontWeight="bold";
                        }
                    }
                    document.getElementById("info_period").innerText ='1d';
                    document.getElementById("info_left").innerText =end_date.Format("yyyy-MM-dd HH:mm:ss");
                    document.getElementById("info_right").innerText =curDate.Format("yyyy-MM-dd HH:mm:ss");
                    $(".ui-rangeSlider-handle.ui-rangeSlider-rightHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    $(".ui-rangeSlider-handle.ui-rangeSlider-leftHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    $(".ui-rangeSlider-label.ui-rangeSlider-rightLabel")[0].style.display="none";
                    $(".ui-rangeSlider-label.ui-rangeSlider-leftLabel")[0].style.display="none";
                });
            };
            $('a[data-toggle="tab"]').on('shown.bs.tab click', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.size() > 0) {
                    if($(this).attr("href") == "#second"){
                        $('#scrollbar_cntr').hide();
                        Controller.table[panel.attr("id")].call(this);
                    }
                    if($(this).attr("href") == "#four"){
                        $('#scrollbar_cntr').show();
                        getjQDateRange();
                        initCpuPageref('0');
                    }
                    if($(this).attr("href") == "#third"){
                        $('#scrollbar_cntr').show();
                        getjQDateRange();
                        initPageref('0');
                    }
                    if($(this).attr("href") == "#first"){
                        $('#scrollbar_cntr').hide();
                    }
                    /*$(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });*/
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            }); 
            $(".btn-first").click(function(){
                /*Backend.api.addtabs("/resources/resc/addtabs/ids/"+ a+"?ref=addtabs");*/ 
                $.ajax({
                        url: 'resources/resc/addtabs',
                        type:'post',
                        data: {ids:a},
                        dataType:'json',
                        success:function(json){
                            return true;
                        }
                    });
            });
            $(".btn-third").click(function(){
                initPageref('0');
            });
            $(".btn-four").click(function(){
                initCpuPageref('0');
            });
            $(".btn-return").click(function(){
                Backend.api.addtabs('resources/resc.html?ref=addtabs','资源列表');
            });
            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
            /*propertyObj=setInterval(function(){
                 initCpuPageref('0');
            },5000);*/
        },
       
        table: {
            second: function () {
                //获取ID
                var a = $("#ids").html();

                // 表格2
                var table2 = $("#table2");
                table2.bootstrapTable({
                    url: 'resources/resc/table2?ids='+a,
                    extend: {
                        //edit_url: 'resources/resc/if_edit',
                        table: 'device_if',
                    },
                    toolbar: '#toolbar2',
                    sortName: 'IfIndex',
                    search: false,
                    searchFormVisible: false,
                    pageSize:50,
                    columns: [
                        [
                            {field: 'order_number', title:__('序列号'),operate:false},
                            // {field: 'device_id', title:__('设备ID')},
                            {field: 'IfDescr', title: __('IfDescr'),operate: 'LIKE %...%'},
                            // {field: 'IfAlias', title: __('接口描述别名'),operate: 'LIKE %...%',formatter:function(data,full){
                            //     if(data == "" || data == null){
                            //         return "-";
                            //     }else{
                            //         return data;
                            //     }
                            // }},
                            {
                                field: 'IfAlias', title: __('接口描述别名'),
                                formatter: function (value, row, index) {
                                     
                                     
                                     if(value){
                                        return '<div style="min-width:50px;">' + value + '</div><input type="text" class="form-control text-center" data-field="' + this.field + '" style="width:100%;display:none;min-width:50px;" value="' + value + '">';
                                    
                                     }else{
                                        return '<div style="min-width:50px;">' + '<span>&nbsp;</span>'+ '</div><input type="text" class="form-control text-center" data-field="' + this.field + '" style="width:100%;display:none;min-width:50px;" value="">';
                               
                                     }
                                  
                                }, events: {
                                    'click div': function (e, value, row, index) {
                                       
                                        $(this).hide();
                                        $(this).next().show().focus();
                                    },
                                    'keyup input': function (e, value, row, index) {
                                        if (e.keyCode == 13 || e.keyCode == 10) {
                                            $(this).trigger("blur");
                                        }
                                    },
                                    'blur input': function (e, value, row, index) {
                                        var that = this;
                                        var value = $(this).val();
                                        //console.log(value);
                                        if(value==""){
                                            $(that).hide();
                                            $(that).prev().show();
                                            return false;
                                        }
                                        if (value != $(that).prev().text()) {
                                            var data = {};
                                            data["row[" + $(that).data("field") + "]"] = value;
                                            Fast.api.ajax({
                                                url:  "resources/resc/editIfAlias?ids=" + row.id,
                                                data: data
                                            }, function (data, ret) {
                                                $(that).hide();
                                                $(that).prev().text(value).show();
                                            });
                                        } else {
                                            $(that).hide();
                                            $(that).prev().show();
                                        }
                                    }
                                }
                            },
                            {field: 'tag_type_id', title: __('标签类型'),visible:false,searchList:tagtypeList,formatter:function(value,row,index){
                                if(row.tagtype==null){
                                    return "-";
                                }else{
                                    return row.tagtype.name;
                                }
                                
                            }},
                            {field: 'tag_id', title: __('标签名称'),visible:false,searchList:tagList,formatter:function(value,row,index){
                                if(row.tag==null||row.tagtype==null){
                                    return "-";
                                }else{
                                    return row.tag.name;
                                }
                            }},
                            

                            {field: 'IfIndex', title: __('接口编号')},
                            {field: 'type', title: __('Type'),operate:false,formatter : Controller.api.formatter.tag,table: table2, events:

                                {'click .labelhref':function(e,value,row){
                                       
                                        //let tag_id=row.tag_id;
                                        let tag_id=$(this).attr("tag_iff");
                                        let name=$(this).attr("name");
                                        let ids=row.id;
                                        
                                        if(basedObj!=null){//判断计时器是否为空
                                        window.clearInterval(basedObj);
                                        basedObj=null;
                                        }
                                        if(propertyObj!=null){//判断计时器是否为空
                                            window.clearInterval(propertyObj);
                                            propertyObj=null;
                                        }
                                        if(table2Obj!=null){//判断计时器是否为空
                                            window.clearInterval(table2Obj);
                                            table2Obj=null;
                                        }
                                        //Controller.label(a,ids,name);
                                        $.setCookie('keep_res',a,365,'/'); //设置365天
                                        $.setCookie('keep_ids',ids,365,'/'); //设置365天
                                        $.setCookie('keep_name',name,365,'/'); //设置365天
                                        $.setCookie('tag_id',tag_id,365,'/'); //设置365天
                                        
                                        Backend.api.closetabs('/admin/resources/resc/label');
                                        Backend.api.addtabs('/admin/resources/resc/label','标签详情');

                                        
                                        
                                    }
                               }
                            },//formatter: Table.api.formatter.normal
                            {field: 'IfOperStatus', title: __('IfOperStatus'), searchList: {"1":__('在线'),"2":__('不在线'),"3":__('测试'),"4":__('未知'),"5":__('休眠'),"6":__('不显示'),"7":__('底层不在线')},formatter:function(data,full){
                                if(data == "1"){
                                    return  '<span style="color:green">在线</span>';
                                }else if(data == "2"){
                                    return '<span style="color:gray">不在线</span>';
                                }else if(data == "3"){
                                    return '<span style="color:gray">测试</span>';
                                }else if(data == "4"){
                                    return '<span style="color:gray">未知</span>';
                                }else if(data == "5"){
                                    return '<span style="color:gray">休眠</span>';
                                }else if(data == "6"){
                                    return '<span style="color:gray">不显示</span>';
                                }else{
                                    return '<span style="color:gray">底层不在线</span>';
                                    
                                }
                            }},
                            //{field: 'IfOperStatus', title: __('IfOperStatus'), table:table2, formatter: Table.api.formatter.status,custom:{1:'success',2:'danger',3:'测试'}},
                            {field: 'operate', title: '标签操作', table: table2, events: Table.api.events.operate, formatter: Table.api.formatter.buttons,buttons: [
                            // {
                            //         name: 'detail',
                            //         text: __('推送到屏幕'),
                            //         title: __('推送到屏幕'),
                            //         classname: 'btn btn-xs btn-primary btn-dialog',
                            //         icon: 'fa fa-list',
                            //         url: 'resources/tag/add_screen?from=interface',
                            //         callback: function (data) {
                            //             Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                            //         },
                            //         visible: function (row) {
                            //             //返回true时按钮显示,返回false隐藏
                            //             return true;
                            //         }
                            // },
                            {
                                name: 'detail',
                                text: '绑定',
                                title: '绑定标签',
                                classname: 'btn btn-xs btn-success btn-dialog',
                                icon: 'fa fa-plus',
                                url: 'resources/resc/if_edit',
                                // callback: function (data) {
                                //     Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                // },
                                // visible: function (row) {
                                //     //返回true时按钮显示,返回false隐藏
                                //     return true;
                                // }
                            },{
                                name: 'detail',
                                text: '解绑',
                                title: '解绑标签',
                                classname: 'btn btn-xs btn-danger btn-dialog',
                                icon: 'fa fa-trash',
                                url: 'resources/resc/if_del',
                                // callback: function (data) {
                                //     Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                // },
                                // visible: function (row) {
                                //     //返回true时按钮显示,返回false隐藏
                                //     return true;
                                // }
                            }]}
                        ]
                    ]
                });
                $('select[name="tag_id"]').attr("disabled","disabled");
                $('select[name="tag_id"]').attr("title","请先选择标签类型");
                $('select[name="tag_type_id"]').on('change',function(){
                    $('select[name="tag_id"]').removeAttr("disabled");
                    var tagname_str = $(this).val();
                    if(tagname_str!=null&&tagname_str!=""){
                        $.ajax({
                            type:"POST",
                            url: 'resources/resc/getTag',
                            data:{type:$(this).val()},
                            dataType:"json",
                            success:function(data){
                                $('select[name="tag_id"]').empty();
                                $('select[name="tag_id"]').append('<option value="" >' + '选择' + '</option>');
                                for(var item of data) {
                                    $('select[name="tag_id"]').append('<option value="'+item.id + '" >' + item.name + '</option>');
                                };
                            }
                        });
                    }else{
                        $('select[name="tag_id"]').attr("disabled","disabled");
                        $('select[name="tag_id"]').attr("title","请先选择标签类型");
                        $('select[name="tag_id"]').empty();
                        $('select[name="tag_id"]').append('<option value="" >' + '选择' + '</option>');
                    }
                })

                // 为表格2绑定事件
                Table.api.bindevent(table2);

                /*table2Obj=setInterval(function(){
                    $('.btn-refresh').click();
                },10000);*/
            },
        },
        label: function(id,ids,name){
            // 初始化表格参数配置
            Table.api.init();

            /* $(window).resize(function(){ 
                console.log("11");
                initJQDateRange();   
            });*/
            var tag_id = $("#tag_id").html();
            $(".flow_push_lable").click(function(obj){
                 $.ajax({
                    url: 'general/screens/index',
                    type:'post',
                    //data: {ids:tag_id,names:names,starttime:starttime3,endtime:endtime3,gradename:gradename3},
                    dataType:'json',
                    success:function(json){
                        if(json.total<1){
                            Toastr.error("请先到屏幕维护-配置屏幕页面，配置屏幕名称");
                        }else{
                           Fast.api.open("resources/tag/add_screen/ids/"+tag_id+"?from=tag","选择屏幕");
                        }
                    }
                });
            });
            if(basedObj!=null){//判断计时器是否为空
                window.clearInterval(basedObj);
                basedObj=null;
            }
            if(propertyObj!=null){//判断计时器是否为空
                window.clearInterval(propertyObj);
                propertyObj=null;
            }
            if(table2Obj!=null){//判断计时器是否为空
                window.clearInterval(table2Obj);
                table2Obj=null;
            }
            var idres = $("#idres").html();
            var a = $("#idslab").html();
            var names = $("#namelab").html();
            var initPagereflab = function(type){
               /* var starttime3='';
                var curDate = new Date();
                var start_date3 = new Date(curDate.getTime() - 24*60*60*1000).Format("yyyy-MM-dd HH:mm");; //前一天
                var end_date3 = new Date().Format("yyyy-MM-dd HH:mm");
                if(type=='1'){//重置
                   $("#start_date3").val(start_date3);
                   $("#end_date3").val(end_date3);
                   document.getElementById("gradename3")[0].selected=true;
                }
                if($("#start_date3").val() != ''){
                   starttime3=$("#start_date3").val();
                }else{
                    starttime3=start_date3;
                }
                var endtime3='';
                if($("#end_date3").val() != ''){
                   endtime3=$("#end_date3").val();
                }else{
                    endtime3=end_date3;
                }
                if (endtime3 < starttime3) {
                      layer.alert('结束时间应大于开始时间',{offset: ['200px', '150px']});
                    
                    return false;
                }
                var gradename3='';
                if($("#gradename3").val() != "") {
                   gradename3=$("#gradename3").find("option:selected").val();
                }*/
                var starttime3 = $("#info_left1").html();
                var endtime3=$("#info_right1").html();
                var gradename3='';

                $.ajax({
                    url: 'resources/resc/regionline',
                    type:'post',
                    data: {ids:tag_id,names:names,starttime:starttime3,endtime:endtime3,gradename:gradename3},
                    dataType:'json',
                    success:function(json){
                        $('#slider1').dateRangeSlider('resize');
                        if(json.length<1){
                            $("#flow_push_lable").hide();
                        }else{
                            $("#flow_push_lable").show();
                            for(var item of json) { // item代表数组里面的元素    
                                $("#flow_push_lable").attr("tag_id", item.tag_id); 
                                Controller.piechart(item, item.name, "regionlink","regionlinkname");
                            }

                        }
                        
                        /*if(labObj!=null){//判断计时器是否为空
                            window.clearInterval(labObj);
                            labObj=null;
                        }
                        labObj=setInterval(function(){
                            initPagereflab(0);
                        },10400);*/
                    }
                });


                  


            };
            require(['jquery-ui', 'jQDateRangeSlider'], function () {
                $("#slider1").bind("userValuesChanged", function(e, data){
                    if(searchflag == true || searchflag1== true){
                    document.getElementById("info_left1").innerText =new Date(data.values.min).Format("yyyy-MM-dd HH:mm:ss");
                    document.getElementById("info_right1").innerText =new Date(data.values.max).Format("yyyy-MM-dd HH:mm:ss");
                    initPagereflab('0');
                    }
                });
                $("#statelink1").click(function(){
                     if($(this).html()=="固定的"){
                        $("#statelink1").html("动态的");
                     }else{
                        $("#statelink1").html("固定的");
                     }
                     
                });
                
                $(".link").click(function(){
                      searchflag = false;
                      searchflag1 = false;
                      var flag = true;
                      var aa=$("#slider1").dateRangeSlider("values");
                      var maxDateTime=new Date(aa.max);
                      var minDateTime=new Date(aa.min);
                      var currDate = new Date();
                      if($(this).attr("nav") == undefined){//上方扩展时间轴
                            $('.links>.link').attr("style", 'font-size: 10px; font-weight: normal; text-decoration: none;');
                            $(this).attr("style", 'font-size: 11px; font-weight: bold; text-decoration: none;');            
                            //时间转换，规则移动最小时间(扩大时间)
                            var changeValue = parseFloat("-"+$(this).attr("zoom"));
                            //设置进度条位置
                            minDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                            maxDateTime=new Date(aa.max);
                            minDateTime = new Date(minDateTime);
                            document.getElementById("info_period1").innerText =this.innerText;

                      }else{ //左移右移事件             
                            //时间转换，加一天
                            var changeValue = parseFloat($(this).attr("nav"));
                            
                            if($("#statelink1").html()=="动态的"){//时间间隔改变
                                //设置进度条位置
                                if(changeValue>0){
                                    maxDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                                    maxDateTime=new Date(maxDateTime);
                                    if(new Date(currDate).getTime()<new Date(maxDateTime).getTime()){
                                        layer.msg('调整时间超出范围');
                                        flag = false;
                                        //maxDateTime=currDate;
                                    }
                                }else{
                                    minDateTime=minDateTime.setSeconds(minDateTime.getSeconds()+changeValue);
                                    minDateTime=new Date(minDateTime);
                                    var currDatemin = currDate.setSeconds(currDate.getSeconds()-zoomListarr1['所有']);
                                    if(new Date(currDatemin).getTime()>new Date(minDateTime).getTime()){
                                       layer.msg('调整时间超出范围');
                                       //minDateTime=new Date(currDatemin);
                                       flag = false;
                                    }
                                }
                                if (flag == true){
                                    var periodname=dateDif(maxDateTime,minDateTime);
                                    document.getElementById("info_period1").innerText=periodname;
                                }
                            }else{//时间间隔固定
                                    maxDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                                    maxDateTime=new Date(maxDateTime);
                                    if(new Date(currDate).getTime()<new Date(maxDateTime).getTime()){
                                        layer.msg('调整时间超出范围');
                                        flag = false;
                                    }
                                    minDateTime=minDateTime.setSeconds(minDateTime.getSeconds()+changeValue);
                                    minDateTime=new Date(minDateTime);
                                    var currDatemin = currDate.setSeconds(currDate.getSeconds()-zoomListarr1['所有']);
                                    if(new Date(currDatemin).getTime()>new Date(minDateTime).getTime()){
                                       layer.msg('调整时间超出范围'); 
                                       flag = false;
                                    }
                            }    
                                               
                      }    

                      if (flag == true){
                          $("#slider1").dateRangeSlider("min", minDateTime);
                          $("#slider1").dateRangeSlider("max", maxDateTime);
                          //设置右上方时间显示doc
                          document.getElementById("info_left1").innerText =minDateTime.Format("yyyy-MM-dd HH:mm:ss");
                          document.getElementById("info_right1").innerText =maxDateTime.Format("yyyy-MM-dd HH:mm:ss");
                          //initPagereflab('0');
                           searchflag = true;
                      }


                     

                });
            });
            var dateDif=function(endTime,startTime){
                //var date = enddate.getTime() - startdate.getTime();
                var usedTime  = new Date(endTime).getTime() - new Date(startTime).getTime();
                var year = Math.floor(usedTime / (365 *24 * 3600 * 1000)); // 计算出年数
                var leavel = usedTime % (365 *24 * 3600 * 1000); // 计算年数后剩余的时间
                
                var months = Math.floor(leavel / (30 *24 * 3600 * 1000)); // 计算出月数
                var leavel1 = leavel % (30 *24 * 3600 * 1000); // 计算月数后剩余的时间
                
                var days = Math.floor(leavel1 / (24 * 3600 * 1000)); // 计算出天数
                var leavel2 = leavel1 % (24 * 3600 * 1000); // 计算天数后剩余的时间
                
                var hours = Math.floor(leavel2 / (3600 * 1000)); // 计算剩余的小时数
                var leavel3 = leavel2 % (3600 * 1000); // 计算剩余小时后剩余的毫秒数
                
                var minutes = Math.floor(leavel3 / (60 * 1000)); // 计算剩余的分钟数
                var leavel4 = leavel3 % (60 * 1000); // 计算剩余分钟后剩余的毫秒数
                
                var seconds = Math.floor(leavel4 / (1000)); // 计算剩余的秒数
                var timename='';
                var time1= year+'年'+months+'月' +days+ '天' + hours + '时' + minutes + '分';
                if(year!=0){timename=year+'y';}
                if(months!=0){timename=timename+' '+months+'m';}
                if(days!=0){timename=timename+' '+days+'d';}
                if(hours!=0){timename=timename+' '+hours+'h';}
                return timename;
            };
            var initJQDateRange = function(){
                require(['jquery-ui', 'jQDateRangeSlider'], function () {
                    var curDate = new Date();     
                    var start_date=new Date(curDate);     
                    var end_date=new Date(curDate);
                   
                    $("#slider1").dateRangeSlider();
                    $("#slider1").dateRangeSlider("bounds", new Date(start_date.setSeconds(start_date.getSeconds()-zoomListarr1['所有'])), new Date(curDate));
                    $("#slider1").dateRangeSlider("min", new Date(end_date.setSeconds(end_date.getSeconds()-86400)));
                    $("#slider1").dateRangeSlider("max", new Date(curDate));
                    $('.links>.link').attr("style", 'font-size: 10px; font-weight: normal; text-decoration: none;');
                    var a=$('.links>.link');
                    for (var i = 0; i < a.length; i++) {
                        if(a[i].innerText=='1d'){
                            $('.links>.link')[i].style.fontSize="11px";
                            $('.links>.link')[i].style.fontWeight="bold";
                        }
                    }
                    document.getElementById("info_period1").innerText ='1d';
                    document.getElementById("info_left1").innerText =end_date.Format("yyyy-MM-dd HH:mm:ss");
                    document.getElementById("info_right1").innerText =curDate.Format("yyyy-MM-dd HH:mm:ss");
                    $(".ui-rangeSlider-handle.ui-rangeSlider-rightHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    $(".ui-rangeSlider-handle.ui-rangeSlider-leftHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    $(".ui-rangeSlider-label.ui-rangeSlider-rightLabel")[0].style.display="none";
                    $(".ui-rangeSlider-label.ui-rangeSlider-leftLabel")[0].style.display="none";
                });
            };
            
            //initPagereflab('0');
             // 搜索
            $("#search_task3").click(function(){
               initPagereflab('0');
            })
            //  重置
            $("#reset_task3").click(function(){    
               initPagereflab('1'); 
            })
            $(".btn-labref").click(function(){
                initPagereflab('0');
            });
                           

            $('a[data-toggle="tab"]').on('shown.bs.tab click', function (e) {                             
                var panel = $($(this).attr("href"));                
                if (panel.size() > 0) {
                    if($(this).attr("href") == "#firstlab"){
                        $('#scrollbar_cntr1').show();
                        initJQDateRange();
                        initPagereflab('0');
                    }
                    if($(this).attr("href") == "#secondlab"){
                        $('#scrollbar_cntr1').hide();
                        Controller.tablelabel[panel.attr("id")].call(this);
                    }

                    /*$(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });*/
                }

                //移除绑定的事件
                $(this).unbind('shown.bs.tab');

            });
            //返回

            $(".btn-return").click(function(){
                if(idres=="0"){
                    Backend.api.closetabs('resources/tag?ref=addtabs','标签名称');
                    Backend.api.addtabs('resources/tag?ref=addtabs','标签名称');
                }else{
                    Backend.api.addtabs('resources/resc/addtabs/ids/'+idres+'?ref=addtabs','资源详情');
                }
            });
            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab"); 
        },
        tablelabel:{
            secondlab: function () {
                var name=$("#namelab").html();
                var ids=$("#idslab").html();
                var tag_id=$("#tag_id").html();
                // 表格3
                var table3 = $("#table3");
                table3.bootstrapTable({
                    url: 'resources/resc/table3?ids='+ids+'&name='+name+'&tag_id='+tag_id,
                    extend: {
                        //edit_url: 'resources/resc/if_edit',
                        table: 'device_if',
                    },
                    toolbar: '#toolbar3',
                    sortName: 'id',
                    search: false,
                    searchFormVisible: false,
                    pageSize:50,
                    columns: [
                        [
                            {field: 'order_number', title:__('序列号'),operate:false},
                            {field: 'devicename', title: __('Name'),operate:false,placeholder: __('模糊查询')},
                            /*{field: 'deviceip', title: __('Ip'),operate:false,placeholder: __('模糊查询')},
                            {field: 'areaname', title: __('Area_id'),operate:false,placeholder: __('模糊查询')},
                            {field: 'regionname', title: __('Region_id'),operate:false,placeholder: __('模糊查询')},*/
                            {field: 'IfDescr', title: __('IfDescr'),operate: 'LIKE %...%'},
                            {field: 'IfAlias', title: __('接口描述别名'),operate: 'LIKE %...%',formatter:function(data,full){
                                if(data == "" || data == null){
                                    return "-";
                                }else{
                                    return data;
                                }
                            }},
                            {field: 'IfIndex', title: __('接口编号')},
                            /*{field: 'type', title: __('Type'),operate:false,formatter : Controller.api.formatter.tag,table: table3, events:{
                                    'click .labelhref':function(e,value,row){
                                        let ids=row.device_id;
                                        let name=$(this).attr("name");
                                        layer.open({
                                            offset: '0px', //右下角弹出
                                            type: 2,
                                            area: ['100%','100%'],
                                            fix: false, //不固定
                                            maxmin: true, //显示或者隐藏缩小 放大 按钮
                                            shadeClose: false,//锁定当前页面必须点 X 才能关闭此页面
                                            shade:0.4,
                                            title: '标签详情',
                                            content: '/admin/resources/resc/label' + "?ids=" + ids+"&name="+name
                                        });
                                    }
                               }
                            },*///formatter: Table.api.formatter.normal
                            {field: 'IfOperStatus', title: __('IfOperStatus'), searchList: {"1":__('在线'),"2":__('不在线')},formatter:function(data,full){
                                if(data == "1"){
                                    return  '<span style="color:green">在线</span>';
                                }else if(data == "2"){
                                    return '<span style="color:gray">不在线</span>';
                                }else{
                                    return data;
                                }
                            }},
                        ]
                    ]
                });

                // 为表格3绑定事件
                Table.api.bindevent(table3);
                /*if(table3Obj==null){//判断计时器是否为空
                    table3Obj=setInterval(function(){
                        $('.btn-refresh').click();
                    },10000);
                }*/
            }
        },
        add: function () {
            Controller.api.bindevent();
            
        },
        edit: function () {
            Controller.api.bindevent();
        },
        if_edit: function(){
            Controller.api.bindevent();

            $("#tag").data("params",function(obj){
                 
                return {row:{key:$("#flag").val()}};
            });
            // $("#address").change(function(){ //监听下拉列表的change事件
            //     var address = $(this).val(); //获取下拉列表选中的值
            //     //console.log(address);
            //     if(address == '1'){
            //         $("#city").html('<option value="1">请选择标签名称</option>'); //js刷新第二个下拉框的值
            //     }else{
            //         $.ajax({
            //             type:'post',
            //             url:'resources/resc/add_label',
            //             data:{key:address},
            //             dataType:'json',
            //             success:function(data){ //请求成功回调函
            //               if(status === 0){
            //                   var option = '<option>请选择标签名称</option>'; //默认值
            //               }else{
            //                   var option = '';
            //                   for(var i=0;i<data.length;i++){ //循环获取返回值，并组装成html代码
            //                   option +='<option value='+data[i].id+'>'+data[i].name+'</option>';
            //                 }
            //               }
            //               $("#city").html(option); //js刷新第二个下拉框的值
            //             }
            //         });
            //     }   
            // });
            // var load_address = $("#address").val();
            // if(load_address == '1'){
            //     $("#city").html('<option value="1">请选择标签名称</option>'); //js刷新第二个下拉框的值
            // }else{
            //     $.ajax({
            //         type:'post',
            //         url:'resources/resc/add_label',
            //         data:{key:load_address},
            //         dataType:'json',
            //         success:function(data){ //请求成功回调函
            //           if(status === 0){
            //               var option = '<option>请选择标签名称</option>'; //默认值
            //           }else{
            //               var option = '';
            //               for(var i=0;i<data.length;i++){ //循环获取返回值，并组装成html代码
            //               option +='<option value='+data[i].id+'>'+data[i].name+'</option>';
            //               }
            //           }
            //           $("#city").html(option); //js刷新第二个下拉框的值
            //         }
            //     });
            // }
        },
        type: function(){
            alert(1);
        },
        if_del: function(){
            Controller.api.bindevent();
            $('#checks').click(()=>{
                if($("#checks").is(":checked")){
                    var test = document.getElementsByName("test[]");
                    for (var i = 0; i < test.length; i++) {
                        test[i].checked = true;
                    }
                }else{
                    var test = document.getElementsByName("test[]");
                    for (var i = 0; i < test.length; i++) {
                        test[i].checked = false;
                    }
                }
            })
            $('#checks1').click(()=>{
                if($("#checks1").is(":checked")){
                    var test = document.getElementsByName("test1[]");
                    for (var i = 0; i < test.length; i++) {
                        test[i].checked = true;
                    }
                }else{
                    var test = document.getElementsByName("test1[]");
                    for (var i = 0; i < test.length; i++) {
                        test[i].checked = false;
                    }
                }
            })
        },
        piechart: function(json, type, id,idname){ //画图 饼图/趋势图   数据   类型(画图的字段后期可扩展)  id
          var myChart = echarts.init(document.getElementById(id));
          var lengthdsname = [];
          for(var item of json.series) { // item代表数组里面的元素
            lengthdsname.push(item.name);
          };

          var flowname=type;
          if(flowname.length > 60){
            var temp = flowname.substring(0,10)+'...';
          }else{
            temp = flowname;
          }

         $('#'+idname).html(temp);
         $('#'+idname).attr("title", flowname);
          var text= temp;
          option = {
            tooltip: {
                trigger: 'axis',
                position: function (pt) {
                    return [pt[0], '10%'];
                },
                formatter:function(params, ticket, callback){
                    var tipString = params[0].name + "<br />";
                    var indexColor;
                    if(id.indexOf("property") != -1 ){
                        for (var i = 0, length = params.length; i < length; i++) {
                            if(params[i].value==""||params[i].value==null){
                                var item_val_str = 0+" %";
                            }else{
                                var item_val_str = params[i].value.toFixed(2)+" %";
                            }
                            indexColor = params[i].color;
                            tipString += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:' + indexColor + '"></span>';
                            tipString += '<span style="color:#fff" data-type ="lineTip" data-val=' + params[i].value + '>' + params[i].seriesName + '：' + item_val_str + '</span><br />';
                        }
                    }else{
                        for (var i = 0, length = params.length; i < length; i++) {
                            var item_val = params[i].value;
                            if(item_val < 1000){
                                if(item_val==""||item_val==null){
                                    var item_val_str = 0+" bps";
                                }else{
                                    var item_val_str = item_val.toFixed(2)+" bps";
                                }
                               //var item_val_str = item_val.toFixed(2)+" bps";
                            }else if(1000 < item_val && item_val < 1000 * 1000){
                               var item_val_str = (item_val/(1000)).toFixed(2)+"Kbps";
                            }else if(1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000){
                               var item_val_str = (item_val/(1000*1000)).toFixed(2)+"Mbps";
                            }else if(1000 * 1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000){
                               var item_val_str = (item_val/(1000*1000*1000)).toFixed(2)+"Gbps";
                            }
                            indexColor = params[i].color;
                            tipString += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:' + indexColor + '"></span>';
                            tipString += '<span style="color:#fff" data-type ="lineTip" data-val=' + params[i].value / 1000 / 1000 + '>' + params[i].seriesName + '：' + item_val_str + '</span><br />';
                        }
                    }
                    return tipString;
                    
                }
            },
            /*title: {
                left: 'center',
                text: text,
            },*/
            legend: {
                x: 'center',
                y:30,
                data:lengthdsname
             },
            toolbox: {
                feature: {
                    dataZoom: {
                        yAxisIndex: 'none'
                    },
                    restore: {},
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data : json.xAxis,
                splitLine: {
                    show: true,
                    lineStyle: {
                        type: 'dashed'
                    }
                }
            },
            yAxis: {
                type: 'value',
                boundaryGap: [0, '100%'],
                axisLabel: {
                    formatter:function(item_val){
                        if(id.indexOf("property") != -1 ){
                            return Math.floor(item_val) + ' %';
                        }else{
                            if(item_val < 1000){
                               return Math.floor(item_val)+" bps";
                            }else if(1000 < item_val && item_val < 1000 * 1000){
                               return Math.floor(item_val/(1000))+"Kbps";
                            }else if(1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000){
                               return Math.floor(item_val/(1000*1000))+"Mbps";
                            }else if(1000 * 1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000){
                               return Math.floor(item_val/(1000*1000*1000))+"Gbps";
                            }
                        }    
                    },
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        type: 'dashed'
                    }
                }
            },
            dataZoom: [{
                show:true,
                //type: 'inside',//鼠标滚动影响图标拖动
                type: 'slider',
                start: 0,
                end: 10,
                zoomOnMouseWheel:false,
            }, {
                start: 0,
                end: 10,
                handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
                handleSize: '80%',
                handleStyle: {
                    color: '#fff',
                    shadowBlur: 3,
                    shadowColor: 'rgba(0, 0, 0, 0.6)',
                    shadowOffsetX: 2,
                    shadowOffsetY: 2
                }
            }],
            series: [
                {
                    name:json.series[0].name,
                    type:'line',
                    smooth:true,
                    symbol: 'none',
                    sampling: 'average',
                    itemStyle: {
                        color: 'rgb(255, 70, 131)'
                    },
                    areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgb(255, 158, 68)'
                        }, {
                            offset: 1,
                            color: 'rgb(255, 70, 131)'
                        }])
                    },
                    data:json.series[0].data
                },{
                    name:json.series[1].name,
                    type:'line',
                    smooth:true,
                    symbol: 'none',
                    sampling: 'average',
                    itemStyle: {
                        color: 'rgb(255, 70, 131)'
                    },
                    areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgb(255, 158, 68)'
                        }, {
                            offset: 1,
                            color: 'rgb(255, 70, 131)'
                        }])
                    },
                    data:json.series[1].data
                }
            ]
          };
         //使用刚指定的配置项和数据显示图表
          myChart.clear();
          myChart.setOption(option,true);
          window.addEventListener("resize", function () {
            myChart.resize();
          });
          myChart.dispatchAction({ // 默认启动 toolbox 中 dataZoom 的区域缩放状态
                type: "takeGlobalCursor",
                key: "dataZoomSelect",
                dataZoomSelectActive: true
          });    
        },
        piechart1: function(json, type, id){ //画图 饼图/趋势图   数据   类型(画图的字段后期可扩展)  id
            var toolTipValue=type;
            var text= type; 
            Highcharts.chart(id, {
                chart: {
                    // zoomType: 'x',
                    // type: 'area'
                },
                title: {
                    style: {
                        // color: 'red',   //字体颜色
                        fontSize:"14px", //字体大小
                        "font-weight": "bold",
                    },
                    text: text,
                    style: {
                        // color: 'red',   //字体颜色
                        fontSize:"14px", //字体大小
                        "font-weight": "bold",
                    },
                    x: -20 //center
                },

                credits: {
                    enabled: false
                },   
                xAxis: {
                    tickmarkPlacement : 'on',// 在刻度上显示时间而不是在刻度之间显示时间
                    tickInterval:1,//刻度的宽度,
                    categories : json.xAxis,
                    splitLine: {
                        show: true,
                        lineStyle: {
                            type: 'dashed'
                        }
                    },
                    // labels:{
                    //     x:45,
                    // },
                    labels : {
                        overflow : 'justify',
                        rotation : 270,
                        formatter: function() {
                            //获取到刻度值
                            var labelVal = this.value;
                            //实际返回的刻度值
                            var reallyVal = labelVal;
                            if(Fast.api.query('gradename') == '1d'){
                                //截取刻度值
                                reallyVal = labelVal.substr(6,4); //月日
                                // console.log(this);
                                if(this.isFirst || this.isLast ){
                                    return '<span style="">'+reallyVal+'</span>'; //月日时分
                                }else if(parseInt(labelVal.substr(8,2)) == 1){
                                    return '<span style="">'+reallyVal+'</span>'; //每月1号变色
                                }else{
                                    return reallyVal;
                                }   
                            }else if(Fast.api.query('gradename') == '1h'){
                                //截取刻度值
                                // console.log(this);
                                if(this.isFirst || this.isLast ){
                                    return '<span style="color:red">'+labelVal.substr(6,10)+'</span>'; //月日时分
                                }else if(parseInt(labelVal.substr(11,5)) == 0){
                                    return '<span style="">'+labelVal.substr(11,5)+'</span>'; //每天的0点变色
                                }else{
                                    return labelVal.substr(11,5); //时分
                                }   
                            }else{
                                //截取刻度值
                                reallyVal = labelVal.substr(11,5); //时分
                                // console.log(this);
                                if(this.isFirst || this.isLast ){
                                    return '<span style="">'+labelVal.substr(6,10)+'</span>'; //月日时分
                                }else{
                                    return reallyVal;
                                }
                            }
                            // return true;
                        }
                    },
                },        
                yAxis: {
                    splitLine: {
                        show: true,
                        lineStyle: {
                            type: 'dashed'
                        }
                    },
                    title: {
                        text: null,
                    },
                    labels: {
                        formatter : function(){//设置纵坐标的样式
                            var item_val = this.value;
                            if(id.indexOf("property") != -1 ){
                                return this.value + ' %';
                            }else{
                                if(item_val < 1000){
                                   return Math.floor(item_val)+" bps";
                                }else if(1000 < item_val && item_val < 1000 * 1000){
                                   return Math.floor(item_val/(1000))+" Kbps";
                                }else if(1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000){
                                   return Math.floor(item_val/(1000*1000))+" Mbps";
                                }else if(1000 * 1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000){
                                   return Math.floor(item_val/(1000*1000*1000))+" Gbps";
                                }else if(1000 * 1000 * 1000*1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000*1000){
                                   return Math.floor(item_val/(1000*1000*1000*1000))+" Tbps";
                                }else if(1000 * 1000 * 1000 *1000*1000<= item_val && item_val < 1000 * 1000 * 1000 * 1000*1000*1000){
                                   return Math.floor(item_val/(1000*1000*1000*1000*1000))+" Pbps";
                                }
                            }
                        }
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }],
                    // min:0,
                    // tickInterval:20,//刻度的宽度             
                },
                legend: {
                      align: 'center',
                      //verticalAlign: 'top',
                      x: -10, //间隔x轴的间隔
                      symbolWidth :30// 间隔　　
                    // enabled: false   //隐藏图例
                },
                tooltip : {
                    formatter : function() {
                        if(type=="001"&&id=="blankScreen"){
                            if(this.point.y=="0.00"){
                                return '<b>' + this.series.name + '</b><br>时间:' + this.key + '<br>'+toolTipValue+'：' + "否";
                            }else{
                                return '<b>' + this.series.name + '</b><br>时间:' + this.key + '<br>'+toolTipValue+'：' + "是";
                            }
                        }else if(id.indexOf("property") != -1 ){
                            var item_val_str = this.point.y.toFixed(2)+' %';
                            return '<b>'+'</b>' + this.key + '<br>'+this.series.name+'：' + item_val_str;
                        }else{
                            var item_val = this.point.y;
                            if(item_val < 1000){
                               var item_val_str = item_val.toFixed(2)+" bps";
                            }else if(1000 < item_val && item_val < 1000 * 1000){
                               var item_val_str = (item_val/(1000)).toFixed(2)+"Kbps";
                            }else if(1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000){
                               var item_val_str = (item_val/(1000*1000)).toFixed(2)+"Mbps";
                            }else if(1000 * 1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000){
                               var item_val_str = (item_val/(1000*1000*1000)).toFixed(2)+"Gbps";
                            }else if(1000 * 1000 * 1000*1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000*1000){
                               var item_val_str = (item_val/(1000*1000*1000*1000)).toFixed(2)+"Tbps";
                            }else if(1000 * 1000 * 1000 *1000*1000<= item_val && item_val < 1000 * 1000 * 1000 * 1000*1000*1000){
                               var item_val_str = (item_val/(1000*1000*1000*1000*1000)).toFixed(2)+"Pbps";
                            }
                            // return '<b>' + this.series.name + '</b><br>时间:' + this.key + '<br>'+toolTipValue+'：' + item_val_str;
                            return '<b>'+'</b>' + this.key + '<br>'+this.series.name+'：' + item_val_str;
                        }
                    }
                },                    
                // series:[{
                //     seriesshowInLegend: false,   //隐藏数据名称
                //     type :'area',
                //     // name:'网信',
                //     data:json.series
                // }]
                series:json.series
            });            
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                tag: function (value, row, index) {
                    value = value === null ? '' : value.toString();
                   
                    //渲染Type
                    var html = [];
                    var arr = value.split(',');
                    $.each(arr, function (i, value) {

                        value = value === null ? '' : value.toString();
                        if (value == '')
                            return true;
                        var color = 'primary';
                        var display = value;
                        if(display!=null&&display!=''&&display!='-'){
                            var ind=display.indexOf("_id_");
                            var tag_iff=display.substring(ind+4,display.length);
                            var namea=display.substring(0,ind);
                          html.push('<a title="点击查看详情" class="labelhref" href="#" name="'+namea+'" tag_iff="'+tag_iff+'"><span class="label label-' + color + '" style="font-size:90%;">' + namea + '</span></a>');
                        }else{
                          html.push('<span title="点击查看详情" class="label label-' + color + '" style="font-size:90%;">' + display + '</span>');
                        }
                    });
                    return html.join(' ');
                },
                taglink: function (column, tag, value, row, index, type) {
                    var table = column.table;
                    type = typeof type === 'undefined' ? 'tag' : type;
                    var options = table ? table.bootstrapTable('getOptions') : {};
                    var html = [];
                    var hidden, visible, url, classname, icon, text, title, refresh, confirm, extend;
                    var fieldIndex = column.fieldIndex;

                    $.each(tag, function (i, j) {
                        if (type === 'operate') {
                            if (j.name === 'dragsort' && typeof row[Table.config.dragsortfield] === 'undefined') {
                                return true;
                            }
                            if (['add', 'edit', 'del', 'multi', 'dragsort'].indexOf(j.name) > -1 && !options.extend[j.name + "_url"]) {
                                return true;
                            }
                        }
                        var attr = table.data(type + "-" + j.name);
                        if (typeof attr === 'undefined' || attr) {
                            hidden = typeof j.hidden === 'function' ? j.hidden.call(table, row, j) : (j.hidden ? j.hidden : false);
                            if (hidden) {
                                return true;
                            }
                            visible = typeof j.visible === 'function' ? j.visible.call(table, row, j) : (j.visible ? j.visible : true);
                            if (!visible) {
                                return true;
                            }
                            url = j.url ? j.url : '';
                            url = typeof url === 'function' ? url.call(table, row, j) : (url ? Fast.api.fixurl(Table.api.replaceurl(url, row, table)) : 'javascript:;');
                            classname = j.classname ? j.classname : 'btn-primary btn-' + name + 'one';
                            icon = j.icon ? j.icon : '';
                            text = j.text ? j.text : '';
                            title = j.title ? j.title : text;
                            refresh = j.refresh ? 'data-refresh="' + j.refresh + '"' : '';
                            confirm = j.confirm ? 'data-confirm="' + j.confirm + '"' : '';
                            extend = j.extend ? j.extend : '';
                            html.push('<a href="' + url + '" class="' + classname + '" ' + (confirm ? confirm + ' ' : '') + (refresh ? refresh + ' ' : '') + extend + ' title="' + title + '" data-table-id="' + (table ? table.attr("id") : '') + '" data-field-index="' + fieldIndex + '" data-row-index="' + index + '" data-button-index="' + i + '"><i class="' + icon + '"></i>' + (text ? ' ' + text : '') + '</a>');
                        }
                    });
                    return html.join(' ');
                },
                tags: function (value, row, index) {                 
                    value = value === null ? '-' : value.toString();
                    // console.log(row);
                    id = row.id === null ? '' : row.id.toString();                 
                    //渲染Type
                    var html = [];
                    var arr = value.split(',');
                    var id_arr = id.split(',');                                                  
                    $.each(arr, function (i, value) {

                        value = value === null ? '' : value.toString();
                        if (value == '')
                            return true;
                        var color = 'primary';
                        var display = value;
                        // console.log(display);                       
                        if(display!=null&&display!=''&&display!='-'){                            
                            var tag_iff=id_arr[i];                            
                            html.push('<a title="点击查看详情" class="labelhref" href="#" name="'+value+'" tag_iff="'+tag_iff+'"><span class="label label-' + color + '" style="font-size:90%; line-height:2">' + value + '</span></a><br/>');
                        }else{
                            // html.push('<span title="点击查看详情" class="label label-' + color + '" style="font-size:90%;">' + display + '</span>');
                            html.push(display);
                        }
                    });
                    return html.join(' ');
                }
            }
        }
    };
    return Controller;
});
